<?php

namespace app\admin\model\xykeep;

use think\Model;
use traits\model\SoftDelete;
use think\Db;

class Course extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'xykeep_course';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text'
    ];

    public function getDisRuleList()
    {
        return ['0' => __('默认规则'),'1' => __('单独设置')];

    }
    
    public function getDisRuleTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_sku']) ? $data['is_sku'] : '');
        $list = $this->getDisRuleList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getIsDisList()
    {
        return ['1' => __('参与'),'0' => __('不参与')];
    }
    
    public function getIsDisTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_sku']) ? $data['is_sku'] : '');
        $list = $this->getIsDisList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }


    public function getStatusList(){
        return ['normal' => __('显示'),'hidden' => __('隐藏')];
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

}
